/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       enum_map.cpp

	$Header: /game/enum_map.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "enum_map.h"

#include <assert.h>
// -----------------------------------------------------------------
// class which maps an enum to a set of strings.  Assumes valid range is >= 0, and that
// values are contiguous.
// -----------------------------------------------------------------
t_enum_map_base::t_enum_map_base( t_string_pair const* pairs, int count,
								  int max_value )
{
	m_keywords.resize( max_value );

  for (int i = 0; i < count; i++)
  {
    assert( pairs[i].value >= 0 && pairs[i].value < max_value );
    m_keywords[pairs[i].value] = pairs[i].keyword;
    m_map[pairs[i].keyword] = pairs[i].value;
  }

#ifndef NDEBUG
	for (int i = 0; i < max_value; i++)
		assert( !m_keywords[i].empty() );
#endif
}

// -----------------------------------------------------------------
// class which maps an enum to a set of strings.  Assumes valid range is >= 0, and that
// values are contiguous.
// -----------------------------------------------------------------
t_enum_map_base::t_enum_map_base( t_char_ptr_pair const* pairs, int count, 
								  int max_value )
{
	m_keywords.resize( max_value );

  for(int i = 0; i < count; i++)
  {
    assert( pairs[i].value >= 0 && pairs[i].value < max_value );
    std::string const & keyword = ( m_keywords[pairs[i].value] = pairs[i].keyword );
    m_map[keyword] = pairs[i].value;
  }

#ifndef NDEBUG
	for (int i = 0; i < max_value; i++)
		assert( !m_keywords[i].empty() );
#endif
}

t_enum_map_base::~t_enum_map_base()
{
}
